package com.ourteam.product.requirement.dao.impl;

import com.ourteam.product.requirement.dao.IProductIssueChangeLogDAO;
import com.ourteam.product.requirement.dao.ProductIssueChangeLog;
import com.ourteam.product.requirement.dao.ProductIssueChangeLogDAOQueryBean;

import net.dao.AbstractSpringDAO;
import net.dao.DataAccessObjectHelper;

import org.apache.commons.beanutils.PropertyUtils;
import org.apache.commons.lang.StringUtils;

import org.springframework.jdbc.core.RowMapper;

import java.sql.ResultSet;
import java.sql.SQLException;

import java.util.ArrayList;
import java.util.List;
import java.util.Map;


/**
 * Template Name : DAO服务对象
 * Template Version : 1
 * Template Last Modfiy Date : Fri Nov 17 11:00:11 CST 2017
 * Auto Generate Date : 2018-05-03 16:45:43
  * Warning ! This file will be overwrite when regenerate !
  *
 */
public class AbstractProductIssueChangeLogDAOJdbcImpl extends AbstractSpringDAO
    implements IProductIssueChangeLogDAO {
    public static final String[] ENTITY_FIELDS = new String[] {
            Id, ProducrIssueId, BeforeChangeStatus, AfterChangeStatus,
            OperatorId, OperateTime, Status, Remarks, OperatorName,
            OperatorPhoto
        };
    public static final String[] ENTITY_PROPERTIES = new String[] {
            _DataObjectProperty.Id, _DataObjectProperty.ProducrIssueId,
            _DataObjectProperty.BeforeChangeStatus,
            _DataObjectProperty.AfterChangeStatus,
            _DataObjectProperty.OperatorId, _DataObjectProperty.OperateTime,
            _DataObjectProperty.Status, _DataObjectProperty.Remarks,
            _DataObjectProperty.OperatorName, _DataObjectProperty.OperatorPhoto
        };
    public static final String[] ENTITY_PK_FIELDS = new String[] { Id };
    public static final String[] ENTITY_AUTO_GEN_PK_FIELDS = new String[] { Id };
    public static final String[] ENTITY_UNIQUE_FIELDS = new String[] {  };
    private static String relatedJoinSQL = null;
    private static String basicFilterSQL = null;
    private DataAccessObjectHelper<ProductIssueChangeLog, ProductIssueChangeLogDAOQueryBean> daoHelper;

    public AbstractProductIssueChangeLogDAOJdbcImpl() {
        super();
        daoHelper = new DataAccessObjectHelper<ProductIssueChangeLog, ProductIssueChangeLogDAOQueryBean>(this);
    }

    protected String getEntityName() {
        return EntityName;
    }

    protected String[] getEntityFields() {
        return ENTITY_FIELDS;
    }

    protected String[] getEntityProperties() {
        return ENTITY_PROPERTIES;
    }

    protected String[] getEntityPKFields() {
        return ENTITY_PK_FIELDS;
    }

    protected String[] getEntityAutoGenPKFields() {
        return ENTITY_AUTO_GEN_PK_FIELDS;
    }

    protected String[] getEntityUniqueFields() {
        return ENTITY_UNIQUE_FIELDS;
    }

    protected String getBaiscQueryFilter() {
        if (basicFilterSQL == null) {
            StringBuffer basicFilterSQLbuffer = new StringBuffer();

            basicFilterSQL = basicFilterSQLbuffer.toString();
        }

        return basicFilterSQL;
    }

    protected String getRelatedJoinSQL() {
        if (relatedJoinSQL == null) {
            StringBuffer relatedJoinSQLBuffer = new StringBuffer();

            relatedJoinSQLBuffer.append(" LEFT JOIN ")
                                .append(com.ourteam.system.dao.ISysUserDAO.EntityName)
                                .append(" RELATED_CZTY5N_SysUser ");

            relatedJoinSQLBuffer.append(" ON ( ");

            relatedJoinSQLBuffer.append(StringUtils.replace(
                    com.ourteam.system.dao.ISysUserDAO.Id,
                    com.ourteam.system.dao.ISysUserDAO.EntityName + ".",
                    "RELATED_CZTY5N_SysUser."));
            relatedJoinSQLBuffer.append(" = ").append(OperatorId);

            relatedJoinSQLBuffer.append(" ) ");

            relatedJoinSQL = relatedJoinSQLBuffer.toString();
        }

        return relatedJoinSQL;
    }

    /**
         * Check Data Unique
         * @param aProductIssueChangeLog
         * @throws Exception
         */
    public boolean checkIsUnique(ProductIssueChangeLog aProductIssueChangeLog)
        throws Exception {
        if (aProductIssueChangeLog == null) {
            return true;
        }

        List valueList = new ArrayList();

        List pkValueList = new ArrayList();

        pkValueList.add(aProductIssueChangeLog.getId());

        return isUnique(valueList.toArray(new Object[valueList.size()]),
            pkValueList.toArray(new Object[pkValueList.size()]));
    }

    /**
     * Insert Data
     * @param aProductIssueChangeLog
     * @throws Exception
     */
    public void insert(ProductIssueChangeLog aProductIssueChangeLog)
        throws Exception {
        super.doInsert(aProductIssueChangeLog);
    }

    /**
         * Batch Insert Datas
         * @param aProductIssueChangeLog
         * @throws Exception
         */
    public void batchInsert(ProductIssueChangeLog[] aProductIssueChangeLogs)
        throws Exception {
        super.doBatchInsert(aProductIssueChangeLogs);
    }

    /**
         * Delete Data
         * @param  final long id         *
         * @throws Exception
         */
    public void delete(final long id) throws Exception {
        super.doDeleteById(new Object[] { new Long(id) });
    }

    /**
     * Delete Datas
     * @param queryBean
     * @throws Exception
     */
    public void delete(ProductIssueChangeLogDAOQueryBean queryBean)
        throws Exception {
        super.doDeleteByQuery(queryBean);
    }

    public void delete(ProductIssueChangeLog aProductIssueChangeLog)
        throws Exception {
        delete(aProductIssueChangeLog.getId());
    }

    /**
     * Update Data Selective
     * @param aProductIssueChangeLog
     * @throws Exception
     */
    public void update(ProductIssueChangeLog aProductIssueChangeLog)
        throws Exception {
        if (aProductIssueChangeLog.getId() == 0) {
            throw new Exception(
                "Can not update object data whith out primary key value");
        }

        super.doUpdate(aProductIssueChangeLog);

        ProductIssueChangeLog tempObj = findById(aProductIssueChangeLog.getId());

        if (tempObj != null) {
            PropertyUtils.copyProperties(aProductIssueChangeLog, tempObj);
        }
    }

    /**
     * Batch Update Datas
     * @param aProductIssueChangeLogs[]
     * @throws Exception
     */
    public void batchUpdate(ProductIssueChangeLog[] aProductIssueChangeLogs)
        throws Exception {
        super.doBatchUpdate(aProductIssueChangeLogs);
    }

    /**
         * Update Data By Condictions
         * @param aProductIssueChangeLog
         * @param aValueCriteria
         * @param aTransaction
         * @throws Exception
         */
    public void update(ProductIssueChangeLog aProductIssueChangeLog,
        ProductIssueChangeLogDAOQueryBean aQueryBean) throws Exception {
        super.doUpdateByQuery(aProductIssueChangeLog, aQueryBean);
    }

    /**
     * Update Data By Condictions
     * @param aQueryBean
     * @throws Exception
     */
    public void update(ProductIssueChangeLogDAOQueryBean aQueryBean)
        throws Exception {
        super.doUpdateByQuery(aQueryBean);
    }

    protected void checkNullValue(ProductIssueChangeLog aProductIssueChangeLog)
        throws Exception {
    }

    /**
     * Get Data By ID
     * @param  final long id         * @return  ${businessObject.name}
     * @throws Exception
     */
    public ProductIssueChangeLog findById(final long id)
        throws Exception {
        ProductIssueChangeLogDAOQueryBean queryBean = new ProductIssueChangeLogDAOQueryBean();

        ProductIssueChangeLogDAOQueryBean.Criteria criteria = queryBean.createCriteria();

        criteria.andIdEqualTo(id);

        //queryBean.setDistinct(true);
        ProductIssueChangeLog[] ProductIssueChangeLogs = query(queryBean);

        if (ProductIssueChangeLogs.length == 0) {
            return null;
        } else {
            return ProductIssueChangeLogs[0];
        }
    }

    /**
         * Query Data
         * @param queryBean
         * @return ProductIssueChangeLog[]
         * @throws Exception
         */
    public ProductIssueChangeLog[] query(
        ProductIssueChangeLogDAOQueryBean queryBean) throws Exception {
        List result = super.doQuery(queryBean,
                new JdbcProductIssueChangeLogRowMapper());

        return (ProductIssueChangeLog[]) result.toArray(new ProductIssueChangeLog[result.size()]);
    }

    /**
     * Query ${businessObject.name} Selective
     * @param queryBean
     * @return Map[]
     * @model
     * @throws Exception
     */
    public Map<String, Object>[] querySelective(
        ProductIssueChangeLogDAOQueryBean queryBean) throws Exception {
        if (queryBean.getSelectProperties().isEmpty()) {
            queryBean.addAllSelectProperties();
        }

        return super.doQuerySelective(queryBean);
    }

    /**
     * Query Data Count
     * @param queryBean
     * @return int
     * @throws Exception
     */
    public int queryCount(ProductIssueChangeLogDAOQueryBean queryBean)
        throws Exception {
        return super.doQueryCount(queryBean);
    }

    public void synchronize(ProductIssueChangeLog[] aProductIssueChangeLogs,
        ProductIssueChangeLogDAOQueryBean queryBean) throws Exception {
        daoHelper.synchronize(aProductIssueChangeLogs, queryBean);
    }

    public void synchronize(ProductIssueChangeLog[] aProductIssueChangeLogs,
        ProductIssueChangeLogDAOQueryBean queryBean,
        net.dao.IDataAccessInterface.ISynchronizeCallback<ProductIssueChangeLog> callBack)
        throws Exception {
        daoHelper.synchronize(aProductIssueChangeLogs, queryBean, callBack);
    }

    public static class JdbcProductIssueChangeLogRowMapper implements RowMapper<ProductIssueChangeLog> {
        public ProductIssueChangeLog mapRow(ResultSet resultSet, int arg1)
            throws SQLException {
            ProductIssueChangeLog object = new ProductIssueChangeLog();

            int columnIndex = 1;

            int __dataType;

            try {
                Object id = null;

                id = resultSet.getObject(columnIndex++);

                object.setIdNull(resultSet.getBoolean(columnIndex++));

                if (id != null) {
                    setBeanValue(object, _DataObjectProperty.Id, id);
                }

                Object producrIssueId = null;

                producrIssueId = resultSet.getObject(columnIndex++);

                object.setProducrIssueIdNull(resultSet.getBoolean(columnIndex++));

                if (producrIssueId != null) {
                    setBeanValue(object, _DataObjectProperty.ProducrIssueId,
                        producrIssueId);
                }

                Object beforeChangeStatus = null;

                beforeChangeStatus = resultSet.getObject(columnIndex++);

                object.setBeforeChangeStatusNull(resultSet.getBoolean(
                        columnIndex++));

                if (beforeChangeStatus != null) {
                    setBeanValue(object,
                        _DataObjectProperty.BeforeChangeStatus,
                        beforeChangeStatus);
                }

                Object afterChangeStatus = null;

                afterChangeStatus = resultSet.getObject(columnIndex++);

                object.setAfterChangeStatusNull(resultSet.getBoolean(
                        columnIndex++));

                if (afterChangeStatus != null) {
                    setBeanValue(object, _DataObjectProperty.AfterChangeStatus,
                        afterChangeStatus);
                }

                Object operatorId = null;

                operatorId = resultSet.getObject(columnIndex++);

                object.setOperatorIdNull(resultSet.getBoolean(columnIndex++));

                if (operatorId != null) {
                    setBeanValue(object, _DataObjectProperty.OperatorId,
                        operatorId);
                }

                Object operateTime = null;

                __dataType = resultSet.getMetaData().getColumnType(columnIndex);

                if ((__dataType == java.sql.Types.DATE) ||
                        (__dataType == java.sql.Types.TIME) ||
                        (__dataType == java.sql.Types.TIMESTAMP)) {
                    operateTime = resultSet.getTimestamp(columnIndex++);
                } else {
                    operateTime = resultSet.getObject(columnIndex++);
                }

                object.setOperateTimeNull(resultSet.getBoolean(columnIndex++));

                if (operateTime != null) {
                    setBeanValue(object, _DataObjectProperty.OperateTime,
                        operateTime);
                }

                Object status = null;

                status = resultSet.getObject(columnIndex++);

                object.setStatusNull(resultSet.getBoolean(columnIndex++));

                if (status != null) {
                    setBeanValue(object, _DataObjectProperty.Status, status);
                }

                Object remarks = null;

                remarks = resultSet.getObject(columnIndex++);

                object.setRemarksNull(resultSet.getBoolean(columnIndex++));

                if (remarks != null) {
                    setBeanValue(object, _DataObjectProperty.Remarks, remarks);
                }

                Object operatorName = null;

                operatorName = resultSet.getObject(columnIndex++);

                object.setOperatorNameNull(resultSet.getBoolean(columnIndex++));

                if (operatorName != null) {
                    setBeanValue(object, _DataObjectProperty.OperatorName,
                        operatorName);
                }

                Object operatorPhoto = null;

                operatorPhoto = resultSet.getObject(columnIndex++);

                object.setOperatorPhotoNull(resultSet.getBoolean(columnIndex++));

                if (operatorPhoto != null) {
                    setBeanValue(object, _DataObjectProperty.OperatorPhoto,
                        operatorPhoto);
                }

                return object;
            } catch (Exception e) {
                throw new SQLException(e.getMessage());
            }
        }
    }
}
